package com.example.helloworldtext2.components;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.example.helloworldtext2.R;
//自定义组件
public class CLike extends LinearLayout {
    private ImageView mIcon;
    private TextView mTitle;

    public CLike(Context context) {
        super(context);
    }

    public CLike(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initView(attrs);
    }

    public CLike(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(attrs);
    }

    private void initView(AttributeSet attributeSet) {
        LayoutInflater.from(getContext()).inflate(R.layout.c_like, this);
        TypedArray array = getContext().obtainStyledAttributes(attributeSet, R.styleable.CLike);

        mIcon = findViewById(R.id.icon);
        mIcon.setImageDrawable(array.getDrawable(R.styleable.CLike_customSrc));

        mTitle = findViewById(R.id.icon_text);
        mTitle.setText(array.getText(R.styleable.CLike_customText));

        array.recycle();
    }
}
